package com.example.rabbitcloud.controller;

import com.example.rabbitcloud.consumer.SimpleMessageReceiver;
import com.example.rabbitcloud.exchange.Produce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * @author cxx
 * @create 2020-02-21 20:48
 **/
@RequestMapping
@RestController
public class HellController {

    @Autowired
    public Produce source;

    @GetMapping("/send/{msg}")
    public String send(@PathVariable String msg){
        MessageChannel channel = source.output ();
        channel.send (new Message<String> () {
            @Override
            public String getPayload() {
                return msg;
            }

            @Override
            public MessageHeaders getHeaders() {
                Map<String, Object> map = new HashMap<> ();
                map.put ("receivedRoutingKey","mykey");
                MessageHeaders messageHeaders = new MessageHeaders (map);
                return messageHeaders;
            }
        });
        return msg;
    }

}
